package com.cecsmsserve.mapper;

import com.cecsmsserve.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cecsmsserve.entity.vo.SignedUserList;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;
import org.apache.ibatis.annotations.Param;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 王郝浠
 * @since 2024-04-15
 */
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from user where id=#{id}")
    User selectById(int id);

    @Select("SELECT name,sex,age,telephone FROM user WHERE id=#{id}")
    SignedUserList selectUserList(int id);

    @Select("select * from user where roleId=#{rid}")
    List<User> selectByRid(int rid);

    @Select("select * from user where roleId=#{arg0} limit #{arg1},#{arg2}")
    List<User> selectByRidByPage(int rid, int start, int size);

    @Select("SELECT * FROM user WHERE name = #{arg0} OR idNum = #{arg1}")
    List<User> selectByNameOrIdNum(String name, String idNum);

    List<HashMap<String, Object>> getUsersSum();

    @Select("SELECT id,roleId,audit_status,audit_remark,username,password,name,sex,birthday,age,idNum,telephone,address,department,point FROM user WHERE username = #{username} AND password = #{password}")
    User login(@Param("username") String username, @Param("password") String password);

    @Select("SELECT * FROM user WHERE audit_status = 0 ORDER BY id DESC LIMIT #{start}, #{size}")
    List<User> selectPendingUsers(@Param("start") int start, @Param("size") int size);

    @Select("SELECT COUNT(*) FROM user WHERE audit_status = 0")
    int countPendingUsers();
}
